<template>
  <a-drawer
    title="延期申请"
    :maskClosable="false"
    width=650
    placement="right"
    :closable="false"
    @close="onClose"
    :visible="myAppEditVisiable"
    style="height: calc(100% - 55px);overflow: auto;padding-bottom: 53px;">

    <a-card title="服务详情">
      <a-row class="row-view">
        <a-col :span="4">
          <label>服务名称：</label>
        </a-col>
        <a-col :span="20">
          <span>{{myApp.serviceName}}</span>
        </a-col>
      </a-row>
      <a-row class="row-view">
        <a-col :span="4">
          <label>服务SN：</label>
        </a-col>
        <a-col :span="20">
          <span>{{myApp.serviceSn}}</span>
        </a-col>
      </a-row>
      <a-row class="row-view">
        <a-col :span="4">
          <label>项目名称：</label>
        </a-col>
        <a-col :span="20">
          <span>{{myApp.projectName}}</span>
        </a-col>
      </a-row>
      <a-row class="row-view">
        <a-col :span="4">
          <label>项目负责人：</label>
        </a-col>
        <a-col :span="20">
          <span>{{myApp.projectManager}}</span>
        </a-col>
      </a-row>
      <a-row class="row-view">
        <a-col :span="4">
          <label>客户：</label>
        </a-col>
        <a-col :span="20">
          <span>{{myApp.client}}</span>
        </a-col>
      </a-row>
      <a-row class="row-view">
        <a-col :span="4">
          <label>申请时间：</label>
        </a-col>
        <a-col :span="20">
          <span>{{myApp.applyTime}}</span>
        </a-col>
      </a-row>
      <a-row class="row-view">
        <a-col :span="4">
          <label>过期时间：</label>
        </a-col>
        <a-col :span="20">
          <span>{{myApp.pastTime}}</span>
        </a-col>
      </a-row>
      <a-row class="row-view">
        <a-col :span="4">
          <label>当前状态：</label>
        </a-col>
        <a-col :span="20">
          <span style="color:red">已过期</span>
        </a-col>
      </a-row>
      <a-row class="row-view">
        <a-col :span="4">
          <label>appkey：</label>
        </a-col>
        <a-col :span="20">
          <span>{{myApp.appkey}}</span>
        </a-col>
      </a-row>
    </a-card>
    <a-divider />

    <a-form :form="form" >
      <a-form-item label='延期月数' v-bind="formItemLayout">
        <a-input-number
          :disabled = disable
          v-model="myApp.delayMonth" :min="3"  style="width: 100%"
                        v-decorator="['delayMonth',
                    {initialValue: '3', rules: [
                    { required: true, message: '不能为空'}
                  ]}]"/>
      </a-form-item>
    </a-form>

    <div class="drawer-bootom-button">
      <a-popconfirm title="确定放弃审核？" @confirm="onClose" okText="确定" cancelText="取消">
        <a-button style="margin-right: .8rem">取消</a-button>
      </a-popconfirm>
      <a-button @click="handleSubmit" :disabled=btnDisable  type="primary" :loading="loading">{{butName}}</a-button>
    </div>
  </a-drawer>
</template>
<script>
import ARow from 'ant-design-vue/es/grid/Row'
import ACol from 'ant-design-vue/es/grid/Col'

const formItemLayout = {
  labelCol: {span: 3},
  wrapperCol: {span: 18}
}
export default {
  name: 'MyAppEdit',
  components: {ACol, ARow},
  props: {
    myAppEditVisiable: {
      default: false
    }
  },
  data () {
    return {
      formItemLayout,
      form: this.$form.createForm(this),
      loading: false,
      myApp: {},
      delayMonth: 3,
      disable: false,
      butName: '提交',
      btnDisable: false
    }
  },
  methods: {
    onClose () {
      this.reset()
      this.$emit('close')
    },
    reset () {
      this.loading = false
      this.myApp = {}
      this.delayMonth = 3
      this.disable = false
      this.butName = '提交'
      this.btnDisable = false
      this.form.resetFields()
    },
    setFormValues ({...record}) {
      this.myApp = record
      this.$post('check/isDelayApply', {
        ...this.myApp
      }).then((r) => {
        let result = r.data
        if (result !== null) {
          this.myApp.delayMonth = result.delayMonth
          this.delayMonth = result.delayMonth
          let obj = {}
          obj['delayMonth'] = result.delayMonth
          this.form.setFieldsValue(obj)
          this.disable = true
          this.btnDisable = true
          this.butName = '延期审核中'
        }
      })
      let fields = []
      Object.keys(record).forEach((key) => {
        if (fields.indexOf(key) !== -1) {
          this.form.getFieldDecorator(key)
          let obj = {}
          obj[key] = record[key]
          this.form.setFieldsValue(obj)
        }
      })
    },
    handleSubmit () {
      this.form.validateFields((err, values) => {
        if (!err) {
          let myApp = this.myApp
          let form = this.form.getFieldsValue()
          myApp.delayMonth = form.delayMonth
          myApp.status = 'PENDING'
          this.$post('check/delayApply', {
            ...myApp
          }).then((r) => {
            this.$emit('success')
          }).catch(() => {
            this.loading = false
          })
        }
      })
    }
  }
}
</script>
<style lang="less" scoped>
  @import "../../../static/less/Common";
  .row-view{ margin:0 0 20px 0; }
</style>
